/*   1:    */ package org.intellij.plugins.relaxNG;
/*   2:    */ 
/*   3:    */

import com.intellij.lang.documentation.DocumentationProvider;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiManager;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.xml.XmlAttribute;
import com.intellij.psi.xml.XmlElement;
import com.intellij.psi.xml.XmlTag;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.xml.util.XmlStringUtil;
import gnu.trove.THashSet;
import org.intellij.plugins.relaxNG.model.descriptors.CompositeDescriptor;
import org.intellij.plugins.relaxNG.model.descriptors.RngElementDescriptor;
import org.intellij.plugins.relaxNG.model.descriptors.RngXmlAttributeDescriptor;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;
import java.util.Iterator;
import java.util.List;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */
/*  18:    */
/*  19:    */
/*  20:    */
/*  21:    */
/*  22:    */
/*  23:    */
/*  24:    */ 
/*  25:    */ public class RngDocumentationProvider
/*  26:    */   implements DocumentationProvider
/*  27:    */ {
/*  28: 48 */   private static final Logger a = Logger.getInstance(RngDocumentationProvider.class);
/*  29:    */   @NonNls
/*  30:    */   private static final String b = "http://relaxng.org/ns/compatibility/annotations/1.0";
/*  31:    */   
/*  32:    */   @Nullable
/*  33:    */   public String generateDoc(PsiElement paramPsiElement1, @Nullable PsiElement paramPsiElement2)
/*  34:    */   {
/*  35: 55 */     XmlElement localXmlElement = (XmlElement)PsiTreeUtil.getParentOfType(paramPsiElement2, new Class[] { XmlTag.class, XmlAttribute.class });
/*  36: 56 */     if ((localXmlElement != null) && (localXmlElement.getManager() == null))
/*  37:    */     {
/*  38: 57 */       a.warn("Invalid context element passed to generateDoc()", new Throwable("<stack trace>"));
/*  39: 58 */       return null;
/*  40:    */     }
/*  41:    */     Object localObject1;
/*  42:    */     Object localObject2;
/*  43:    */     Object localObject3;
/*  44:    */     Object localObject4;
/*  45:    */     Object localObject5;
/*  46:    */     Object localObject6;
/*  47: 60 */     if ((localXmlElement instanceof XmlTag))
/*  48:    */     {
/*  49: 61 */       localObject1 = (XmlTag)localXmlElement;
/*  50: 62 */       localObject2 = ((XmlTag)localObject1).getDescriptor();
/*  51: 63 */       if ((localObject2 instanceof CompositeDescriptor))
/*  52:    */       {
/*  53: 64 */         localObject3 = new StringBuilder();
/*  54: 65 */         localObject4 = (CompositeDescriptor)localObject2;
/*  55: 66 */         localObject5 = ((CompositeDescriptor)localObject4).getElementPatterns();
/*  56: 67 */         localObject6 = ContainerUtil.newIdentityTroveSet();
/*  57: 68 */         for (Object localObject8 : localObject5)
/*  58:    */         {
/*  59: 69 */           PsiElement localPsiElement = ((CompositeDescriptor)localObject4).getDeclaration(localObject8.getLocation());
/*  60: 70 */           if (((localPsiElement instanceof XmlTag)) && (((THashSet)localObject6).add(localPsiElement)))
/*  61:    */           {
/*  62: 71 */             if (((StringBuilder)localObject3).length() > 0) {
/*  63: 72 */               ((StringBuilder)localObject3).append("<hr>");
/*  64:    */             }
/*  65: 74 */             ((StringBuilder)localObject3).append(a((XmlTag)localPsiElement, ((XmlTag)localObject1).getLocalName(), "Element"));
/*  66:    */           }
/*  67:    */         }
/*  68: 77 */         return a((StringBuilder)localObject3);
/*  69:    */       }
/*  70: 78 */       if ((localObject2 instanceof RngElementDescriptor))
/*  71:    */       {
/*  72: 79 */         localObject3 = (RngElementDescriptor)localObject2;
/*  73: 80 */         localObject4 = ((RngElementDescriptor)localObject3).getDeclaration();
/*  74: 81 */         if ((localObject4 instanceof XmlTag)) {
/*  75: 82 */           return a(a((XmlTag)localObject4, ((XmlTag)localObject1).getLocalName(), "Element"));
/*  76:    */         }
/*  77:    */       }
/*  78:    */     }
/*  79: 85 */     else if ((localXmlElement instanceof XmlAttribute))
/*  80:    */     {
/*  81: 86 */       localObject1 = (XmlAttribute)localXmlElement;
/*  82: 87 */       localObject2 = ((XmlAttribute)localObject1).getDescriptor();
/*  83: 88 */       if ((localObject2 instanceof RngXmlAttributeDescriptor))
/*  84:    */       {
/*  85: 89 */         localObject3 = (RngXmlAttributeDescriptor)localObject2;
/*  86: 90 */         localObject4 = new StringBuilder();
/*  87: 91 */         localObject5 = ContainerUtil.newIdentityTroveSet(((RngXmlAttributeDescriptor)localObject3).getDeclarations());
/*  88: 92 */         for (localObject6 = ((Collection)localObject5).iterator(); ((Iterator)localObject6).hasNext();)
/*  89:    */         {
/*  90: 92 */           ??? = (PsiElement)((Iterator)localObject6).next();
/*  91: 93 */           if ((??? instanceof XmlTag))
/*  92:    */           {
/*  93: 94 */             if (((StringBuilder)localObject4).length() > 0) {
/*  94: 95 */               ((StringBuilder)localObject4).append("<hr>");
/*  95:    */             }
/*  96: 97 */             ((StringBuilder)localObject4).append(a((XmlTag)???, ((RngXmlAttributeDescriptor)localObject3).getName(), "Attribute"));
/*  97:    */           }
/*  98:    */         }
/*  99:    */       }
/* 100:    */     }
/* 101:101 */     else if ((paramPsiElement1 instanceof XmlTag))
/* 102:    */     {
/* 103:102 */       return a(a((XmlTag)paramPsiElement1, ((XmlTag)paramPsiElement1).getLocalName(), "Element"));
/* 104:    */     }
/* 105:104 */     return null;
/* 106:    */   }
/* 107:    */   
/* 108:    */   private static String a(StringBuilder paramStringBuilder)
/* 109:    */   {
/* 110:108 */     if (paramStringBuilder == null) {
/* 111:108 */       return null;
/* 112:    */     }
/* 113:109 */     String str = paramStringBuilder.toString().replaceAll("\n", "<br>");
/* 114:110 */     if (!str.startsWith("<html>")) {
/* 115:111 */       str = XmlStringUtil.wrapInHtml(str);
/* 116:    */     }
/* 117:113 */     return str;
/* 118:    */   }
/* 119:    */   
/* 120:    */   private static StringBuilder a(XmlTag paramXmlTag, String paramString1, String paramString2)
/* 121:    */   {
/* 122:117 */     if (paramXmlTag.getNamespace().equals("http://relaxng.org/ns/structure/1.0"))
/* 123:    */     {
/* 124:118 */       StringBuilder localStringBuilder = new StringBuilder();
/* 125:119 */       localStringBuilder.append(paramString2).append(": <b>").append(paramString1).append("</b><br>");
/* 126:120 */       XmlTag[] arrayOfXmlTag = paramXmlTag.findSubTags("documentation", "http://relaxng.org/ns/compatibility/annotations/1.0");
/* 127:121 */       for (Object localObject2 : arrayOfXmlTag)
/* 128:    */       {
/* 129:122 */         localStringBuilder.append(localObject2.getValue().getTrimmedText());
/* 130:123 */         localStringBuilder.append("\n");
/* 131:    */       }
/* 132:125 */       ??? = (XmlTag)PsiTreeUtil.getNextSiblingOfType(paramXmlTag, XmlTag.class);
/* 133:126 */       if ((??? != null) && 
/* 134:127 */         ("documentation".equals(((XmlTag)???).getLocalName())) && ("http://relaxng.org/ns/compatibility/annotations/1.0".equals(((XmlTag)???).getNamespace()))) {
/* 135:128 */         localStringBuilder.append(((XmlTag)???).getValue().getTrimmedText());
/* 136:    */       }
/* 137:131 */       return localStringBuilder;
/* 138:    */     }
/* 139:133 */     return null;
/* 140:    */   }
/* 141:    */   
/* 142:    */   @Nullable
/* 143:    */   public PsiElement getDocumentationElementForLink(PsiManager paramPsiManager, String paramString, PsiElement paramPsiElement)
/* 144:    */   {
/* 145:138 */     return null;
/* 146:    */   }
/* 147:    */   
/* 148:    */   @Nullable
/* 149:    */   public PsiElement getDocumentationElementForLookupItem(PsiManager paramPsiManager, Object paramObject, PsiElement paramPsiElement)
/* 150:    */   {
/* 151:143 */     return null;
/* 152:    */   }
/* 153:    */   
/* 154:    */   @Nullable
/* 155:    */   public String getQuickNavigateInfo(PsiElement paramPsiElement1, PsiElement paramPsiElement2)
/* 156:    */   {
/* 157:148 */     return null;
/* 158:    */   }
/* 159:    */   
/* 160:    */   public List<String> getUrlFor(PsiElement paramPsiElement1, PsiElement paramPsiElement2)
/* 161:    */   {
/* 162:152 */     return null;
/* 163:    */   }
/* 164:    */   
/* 165:    */   public int hashCode()
/* 166:    */   {
/* 167:156 */     return 0;
/* 168:    */   }
/* 169:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.intellij.plugins.relaxNG.RngDocumentationProvider

 * JD-Core Version:    0.7.0.1

 */